package com.kaibes.platform.article.admin.plugin;

import java.util.List;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.kaibes.module.user.pojo.User;
import com.kaibes.platform.article.db.entity.Article;
import com.kaibes.platform.article.db.entity.ArticleComment;
import com.kaibes.web.thymeleaf.ThymeleafConfig;

@Component
public class ArticlePlugin implements InitializingBean {

	@Autowired
	private ThymeleafConfig thymeleafConfig;
	@Autowired(required = false)
    private List<ArticleModified> articleModifiedList;
    @Autowired(required = false)
    private List<ArticleCommentModified> commentModifieds;

    public void modified(User user, Article article) {
        if (articleModifiedList != null) {
            for (ArticleModified articleModified : articleModifiedList) {
                articleModified.modified(user, article);
            }
        }
    }
    
    public void modified(User user, ArticleComment comment) {
        if (commentModifieds != null) {
            for (ArticleCommentModified commentModified : commentModifieds) {
                commentModified.modified(user, comment);
            }
        }
    }

	@Override
	public void afterPropertiesSet() throws Exception {
		thymeleafConfig.putStaticVariable("articlePlugin", this);
	}
    
}
